package com.dkd.http.controller;

import com.dkd.entity.OrderCollectEntity;
import com.dkd.entity.OrderSkuVo;
import com.dkd.entity.vo.BarCharCollect;
import com.dkd.service.OrderCollectService;
import com.dkd.service.OrderService;
import com.dkd.vo.Pager;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.Date;
import java.util.List;


/**
 * 报表
 */
@RestController
@RequestMapping("/report")
@Api(tags = "报告相关业务")
@Slf4j
@RequiredArgsConstructor
public class ReportController {
    private final OrderService orderService;
    private final OrderCollectService reportService;
    @GetMapping("/skuCollect/{innerCode}/{start}/{end}")
    public List<OrderSkuVo> getSupplyCount(@PathVariable("innerCode") String innerCode,
                                           @PathVariable("start") @DateTimeFormat(pattern = "yyyy-MM-dd") Date start,
                                           @PathVariable("end") @DateTimeFormat(pattern = "yyyy-MM-dd") Date end
    ){

        log.info("innerCode={},start={},end={}",innerCode,start,end);
        return orderService.getSupplyCount(innerCode,start,end);
    }

    /**
     * 根据地区汇总销售额数据
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/regionCollect/{start}/{end}")
    public BarCharCollect getRegionCollect(
            @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate start,
            @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        return reportService.getCollectByRegion(start,end);
    }

    /**
     * 获取合作商一定日期范围的收益情况
     * @param partnerId
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/collectReport/{partnerId}/{start}/{end}")
    public BarCharCollect getCollectReport(@PathVariable Integer partnerId,
                                           @PathVariable  @DateTimeFormat(pattern = "yyyy-MM-dd")  LocalDate start,
                                           @PathVariable  @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        return reportService.getCollect(partnerId,start,end);
    }

    /**
     * 获取一定日期范围之内的合作商分成汇总数据
     * @param pageIndex
     * @param pageSize
     * @param partnerId
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/partnerCollect")
    public Pager<OrderCollectEntity> getPartnerCollect(
            @RequestParam(value = "pageIndex",required = false,defaultValue = "1") Long pageIndex,
            @RequestParam(value = "pageSize",required = false,defaultValue = "10") Long pageSize,
            @RequestParam(value = "partnerId",required = false,defaultValue = "") Integer partnerId,
            @RequestParam(value = "start",required = true,defaultValue = "") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate start,
            @RequestParam(value = "end",required = true,defaultValue = "") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end
    ){
        return reportService.getPartnerCollect(pageIndex,pageSize,partnerId,start,end);
    }
    /**
     * 获取最近12条分账信息
     * @param partnerId
     * @return
     */
    @GetMapping("/top12Collect/{partnerId}")
    public List<OrderCollectEntity> getTop12Collect(@PathVariable Integer partnerId){
        return reportService.getTop12(partnerId);
    }
    //获取销售前几的商品
    @GetMapping("/skuTop/{topValue}/{start}/{end}")
    public List<OrderSkuVo> getBusinessTop10Skus(@PathVariable Integer topValue,
                                                 @PathVariable  @DateTimeFormat(pattern = "yyyy-MM-dd")  LocalDate start,
                                                 @PathVariable  @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
     return orderService.getBusinessTop10Skus(topValue,start,end);
    }


    /**
     * 获取销售额统计
     * @param collectType
     * @param start
     * @param end
     * @return
     */
    @GetMapping("/amountCollect/{collectType}/{start}/{end}")
    public BarCharCollect getAmountCollect(@PathVariable Integer collectType,
                                           @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate start,
                                           @PathVariable  @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        return reportService.getAmountCollect(collectType,start,end);
    }
    /**
     * 获取一定时间范围之内的收入
     * @param partnerId
     * @return
     */
    @GetMapping("/orderAmount")
    public Long getCurrentDayAmount(@RequestParam(value = "partnerId",required = false,defaultValue = "") Integer partnerId,
                                    @RequestParam(value = "innerCode",required = false,defaultValue = "") String innerCode,
                                    @RequestParam(value = "start") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate start,
                                    @RequestParam(value = "end") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        return orderService.getAmount(partnerId,innerCode,start,end);
    }

    /**
     * 获取一定时间范围之内的订单总数
     * @param partnerId
     * @return
     */
    @GetMapping("/orderCount")
    public Long getCurrentDayCount(@RequestParam(value = "partnerId",required = false,defaultValue = "") Integer partnerId,
                                    @RequestParam(value = "innerCode",required = false,defaultValue = "") String innerCode,
                                    @RequestParam(value = "start") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate start,
                                    @RequestParam(value = "end") @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end){
        return orderService.getCount(partnerId,innerCode,start,end);
    }



}
